//
//  changeSuccessViewController.m
//  dongfengTest
//
//  Created by wxt on 2021/3/18.
//

#import "ChangeSuccessViewController.h"
#import "ViewController.h"
@interface ChangeSuccessViewController ()
@property(nonatomic,strong)NSTimer *timer;
@property(nonatomic,assign)int count;
@property(nonatomic,strong)TKLlable * signMeLab;
@end

@implementation ChangeSuccessViewController
-(void)viewWillAppear:(BOOL)animated{
    
    self.navigationController.navigationBarHidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [self.timer invalidate];
      self.timer = nil;
    self.navigationController.navigationBarHidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = Wcolor;
    // Do any additional setup after loading the view.
    [self addUIView];
    
    
    // Do any additional setup after loading the view.
}
-(void)addUIView{
   

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
       [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    self.count = 3;
    tklImgView * topImg = [[tklImgView alloc]initWithFrame:CGRectMake(50, 50, kWidth-100, kWidth-100 )];
    topImg.image = [UIImage imageNamed:@"编组 2"];
    [self.view addSubview:topImg];
    
    TKLlable * signLab = [TKLlable labelWithFrame:CGRectMake(kWidth/2-50, CGRectGetMaxY(topImg.frame), 100, 20) text:@"操作成功" textColor:Bcolor font:Font_6(16) textAlignment:Textcenter backgroundColor:Ccolor];
    [self.view addSubview:signLab];
    
    TKLlable * messLab = [TKLlable labelWithFrame:CGRectMake(10, CGRectGetMaxY(signLab.frame)+15, kWidth-20, 18) text:[NSString stringWithFormat:@"您已成功修改%@密码",self.pushType] textColor:JhColor(165, 165, 165) font:Font_6(14) textAlignment:Textcenter backgroundColor:Ccolor];
    [self.view addSubview:messLab];
    
    
    self.signMeLab = [TKLlable labelWithFrame:CGRectMake(10, CGRectGetMaxY(messLab.frame), kWidth-20, 20) text:@"3秒后将自动返回登录页" textColor:JhColor(51, 51, 51) font:Font_6(14) textAlignment:Textcenter backgroundColor:Ccolor];
    [self.view addSubview:self.signMeLab];
    
    UIButton * backBtn = [UIButton createBtnFrame:CGRectMake(kWidth/2-50, CGRectGetMaxY(self.signMeLab.frame)+20, 100, 30) title:@"返回首页" bgImageName:@"" action:^(UIButton *button) {
        
//        NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
//        [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
        
        UIViewController *rootVC = self.presentingViewController;
                while(rootVC.presentingViewController) {
                    
                   rootVC= rootVC.presentingViewController;
                    
                 }
                
        [rootVC dismissViewControllerAnimated:YES completion:nil];
    }];
    
    backBtn.backgroundColor = JhColor(22, 119, 255);
    backBtn.layer.masksToBounds = YES;
    backBtn.layer.cornerRadius = 15;
    
//    UIButton * backBtn = [UIButton createBtnFrame:CGRectMake(kWidth/2-50, CGRectGetMaxY(signMeLab.frame)+20, 100, 30) title:@"返回登录页" bgImageName:@"" textcolor:JhColor(151, 151, 151) laycolor:JhColor(204, 204, 204) action:^(UIButton *button) {
//                NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
//                      [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
//        UIViewController *rootVC = self.presentingViewController;
//        while(rootVC.presentingViewController) {
//        rootVC= rootVC.presentingViewController;
//        }
//
//     [rootVC dismissViewControllerAnimated:YES completion:nil];
//        //
//    }];
    

    [self.view addSubview:backBtn];
}
- (void)timerAction{
//    
    self.count -=1;
    NSString * titStr = [NSString stringWithFormat:@"%d秒后自动返回登录首页",self.count];
    self.signMeLab.text = titStr;
    if (self.count <=0) {
       
        
        UIViewController *rootVC = self.presentingViewController;
                while(rootVC.presentingViewController) {
                    
                   rootVC= rootVC.presentingViewController;
                    
                 }
                
        [rootVC dismissViewControllerAnimated:YES completion:nil];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
